package com.community.backend.controller;

import com.community.backend.pojo.Maintenance;
import com.community.backend.pojo.dto.MaintenanceQueryDTO;
import com.community.backend.service.MaintenanceService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/maintenance")
@Slf4j
public class MaintenanceController {
    private final MaintenanceService maintenanceService;

    public MaintenanceController(MaintenanceService maintenanceService) {
        this.maintenanceService = maintenanceService;
    }


    @GetMapping("/page")
    public Result<PageResult> pageWater(MaintenanceQueryDTO maintenanceQueryDTO) {
        PageResult pageResult = maintenanceService.pageQuery(maintenanceQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result save(@RequestBody Maintenance maintenance) {
        log.info("添加报修信息参数：{}", maintenance);
        maintenanceService.save(maintenance);
        return Result.success("添加成功");
    }
    @PutMapping
    public Result Update(@RequestBody Maintenance maintenance) {
        maintenanceService.update(maintenance);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable String id) {
        maintenanceService.deleteById(id);
        return Result.success("删除成功");
    }
}
